﻿using Md.Api.Model;
using Md.Api.Model.Manage.SysDictData.Request;
using Md.Api.Service.Manage.SysDictData;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 系统字典数据
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/system/dict/data")]
public class SysDictDataController : ControllerBase
{
    /// <summary>
    /// 通过字典编码删除系统字典数据服务
    /// </summary>
    public DeleteSysDictDataByDictCodeService deleteSysDictDataByDictCodeService { get; set; }
    /// <summary>
    /// 通过字典编码删除系统字典数据
    /// </summary>
    /// <param name="dictCodes">字典编码多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{dictCodes}")]
    public async Task<ResponseMessageModel> DeleteSysDictDataByDictCode(string dictCodes, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteSysDictDataByDictCodeModel();

        model.DictCodes = dictCodes;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteSysDictDataByDictCodeService.Execute(model));
    }

    /// <summary>
    /// 添加系统字典数据服务
    /// </summary>
    public InsertSysDictDataService insertSysDictDataService { get; set; }
    /// <summary>
    /// 添加系统字典数据
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertSysDictData([FromBody] RequestInsertSysDictDataModel model)
    {
        return await Task.Run(() => insertSysDictDataService.Execute(model));
    }

    /// <summary>
    /// 通过字典编码更新系统字典数据服务
    /// </summary>
    public UpdateSysDictDataByDictCodeService updateSysDictDataByDictCodeService { get; set; }
    /// <summary>
    /// 通过字典编码更新系统字典数据
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateSysDictDataByDictCode([FromBody] RequestUpdateSysDictDataByDictCodeModel model)
    {
        return await Task.Run(() => updateSysDictDataByDictCodeService.Execute(model));
    }

    /// <summary>
    /// 通过字典编码获取系统字典数据服务
    /// </summary>
    public GetSysDictDataByDictCodeService getSysDictDataByDictCodeService { get; set; }
    /// <summary>
    /// 通过字典编码获取系统字典数据
    /// </summary>
    /// <param name="dictCode">字典编码</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{dictCode}")]
    public async Task<ResponseMessageModel> GetSysDictDataByDictCode(long dictCode, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetSysDictDataByDictCodeModel();

        model.DictCode = dictCode;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getSysDictDataByDictCodeService.Execute(model));
    }

    /// <summary>
    /// 通过字典类型获取字典数据列表服务
    /// </summary>
    public GetSysDictDataListByDictTypeService getSysDictDataListByDictTypeService { get; set; }
    /// <summary>
    /// 通过字典类型获取字典数据列表
    /// </summary>
    /// <param name="dictType">字典类型</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("type/{dictType}"), HttpGet]
    public async Task<ResponseMessageModel> GetSysDictDataListByDictType(string dictType, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetSysDictDataListByDictTypeModel();

        model.DictType = dictType;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getSysDictDataListByDictTypeService.Execute(model));
    }

    /// <summary>
    /// 获取系统字典数据列表服务
    /// </summary>
    public GetSysDictDataListService getSysDictDataListService { get; set; }
    /// <summary>
    /// 获取系统字典数据列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetSysDictDataList([FromBody] RequestGetSysDictDataListModel model)
    {
        return await Task.Run(() => getSysDictDataListService.Execute(model));
    }

    /// <summary>
    /// 分页获取系统字典数据列表服务
    /// </summary>
    public GetSysDictDataPageListService getSysDictDataPageListService { get; set; }
    /// <summary>
    /// 分页获取系统字典数据列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetSysDictDataPageList([FromBody] RequestGetSysDictDataPageListModel model)
    {
        return await Task.Run(() => getSysDictDataPageListService.Execute(model));
    }
}

